import { NodeSize } from '../config'

export default function regexEval(flow) {
  flow.register('RegexEval', ({ PolygonNode, PolygonNodeModel, h }) => {
    class Node extends PolygonNode {
      getIconShape() {
        return h(
          'svg',
          {
            width: NodeSize,
            height: NodeSize,
            viewBox: '0 0 1024 1024'
          },
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M943.957333 906.50819l-74.093714-74.069333a117.711238 117.711238 0 0 0 20.455619-66.413714 118.491429 118.491429 0 0 0-118.369524-118.393905c-28.867048 0-54.979048 10.776381-75.556571 27.989333l-14.896762 14.896762c-17.212952 20.553143-27.989333 46.689524-27.989333 75.50781a118.54019 118.54019 0 0 0 118.418285 118.393905c23.942095 0 46.201905-7.265524 64.853334-19.529143l74.386285 74.386285 32.792381-32.768z m-172.007619-58.660571c-45.153524 0-81.846857-36.717714-81.846857-81.822476s36.717714-81.822476 81.846857-81.822476c45.129143 0 81.798095 36.717714 81.798096 81.822476s-36.668952 81.822476-81.798096 81.822476z'
            }
          ),
          h(
            'path',
            {
              fill: '#FFECCE',
              d: 'M773.827048 598.162286V231.058286h-543.695238v543.719619h367.104l84.284952-84.284953 14.896762-14.896762 77.409524-77.433904z m-364.202667-2.80381l-14.848-43.227428h-73.020952l-14.604191 43.227428h-28.672l62.488381-184.929524h34.864762l62.488381 184.929524h-28.696381z m176.128-41.081905c0 26.89219-19.065905 41.106286-47.055238 41.106286H462.994286v-184.929524h71.899428c29.403429 0 44.885333 13.507048 44.885334 38.960762v20.821334c0 12.604952-3.730286 22.747429-15.725715 29.379047 13.04381 4.583619 21.674667 15.555048 21.674667 33.060572v21.601523z m27.550476-11.629714v-79.481905c0-35.644952 18.870857-55.417905 64.073143-55.417904a232.838095 232.838095 0 0 1 45.958095 4.924952l2.145524 0.487619-2.998857 24.771048-2.535619-0.463238a273.432381 273.432381 0 0 0-41.764572-3.754667c-28.525714 0-36.766476 7.41181-36.766476 30.841905v76.751238c0 23.430095 8.240762 30.841905 36.766476 30.841905 10.703238 0 28.086857-1.365333 41.764572-3.754667l2.535619-0.463238 2.998857 24.746666-2.145524 0.512a234.691048 234.691048 0 0 1-45.958095 4.924953c-45.177905-0.024381-64.073143-19.846095-64.073143-55.466667z'
            }
          ),
          h(
            'path',
            {
              fill: '#FFECCE',
              d: 'M551.66781 470.186667v-20.284953c0-9.849905-4.949333-14.57981-18.090667-14.579809h-42.447238v53.491809h38.643809c16.384 0.024381 21.894095-7.143619 21.894096-18.627047zM534.089143 513.731048h-42.983619v56.758857h44.324571c15.555048 0 22.162286-6.314667 22.162286-18.090667v-18.944c0.024381-12.678095-6.680381-19.72419-23.503238-19.72419zM329.557333 526.969905h57.636572l-28.818286-89.380572z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M230.13181 231.058286h543.695238v367.104l41.447619-41.423238V189.635048h-626.590477v626.566095h367.128381l41.423239-41.423238H230.13181z'
            }
          ),
          h(
            'path',
            {
              fill: '#3D6480',
              d: 'M340.967619 410.428952l-62.488381 184.929524h28.672l14.604191-43.227428h73.020952l14.848 43.227428h28.672l-62.488381-184.929524h-34.840381z m-11.410286 116.540953l28.842667-89.380572 28.818286 89.380572h-57.660953zM564.077714 499.590095c11.971048-6.631619 15.725714-16.774095 15.725715-29.379047v-20.821334c0-25.453714-15.481905-38.960762-44.885334-38.960762h-71.923809v184.929524h75.678476c27.964952 0 47.055238-14.214095 47.055238-41.106286v-21.625904c0.024381-17.505524-8.606476-28.452571-21.650286-33.036191z m-72.947809-64.243809h42.447238c13.141333 0 18.090667 4.705524 18.090667 14.579809v20.284953c0 11.483429-5.534476 18.651429-21.894096 18.651428h-38.643809v-53.51619z m66.486857 117.052952c0 11.776-6.607238 18.090667-22.162286 18.090667h-44.324571v-56.758857h42.983619c16.798476 0 23.527619 7.046095 23.527619 19.748571v18.919619zM725.479619 592.65219l-2.998857-24.746666-2.535619 0.463238c-13.677714 2.413714-31.036952 3.754667-41.764572 3.754667-28.525714 0-36.766476-7.41181-36.766476-30.841905v-76.751238c0-23.430095 8.240762-30.841905 36.766476-30.841905 10.703238 0 28.086857 1.365333 41.764572 3.754667l2.535619 0.463238 2.998857-24.771048-2.145524-0.487619a232.838095 232.838095 0 0 0-45.958095-4.924952c-45.202286 0-64.073143 19.797333-64.073143 55.417904v79.481905c0 35.620571 18.870857 55.417905 64.073143 55.417905 13.677714 0 32.841143-1.926095 45.958095-4.924952l2.145524-0.463239z'
            }
          )
        )
      }

      getLabelShape() {
        return h(
          'text',
          {
            fill: '#000000',
            fontSize: 12,
            x: NodeSize / 2,
            y: NodeSize + 20,
            textAnchor: 'middle',
            dominantBaseline: 'middle'
          },
          '正则表达式 '
        )
      }

      getShape() {
        const { x, y, width, height } = this.getAttributes()
        const transform = `matrix(1 0 0 1 ${x - width / 2} ${y - height / 2})`
        return h(
          'g',
          {
            transform
          },
          [
            h(
              'rect',
              {
                rx: 5,
                ry: 5,
                width: NodeSize,
                height: NodeSize,
                fill: '#fff',
                stroke: '#3D6380',
                strokeWidth: 1
              }
            ),
            this.getIconShape(),
            this.getLabelShape()
          ]
        )
      }
    }
    class Model extends PolygonNodeModel {
      constructor(data, graphModel) {
        super(data, graphModel)
        this.points = [
          [NodeSize / 2, 0],
          [NodeSize, NodeSize / 2],
          [NodeSize / 2, NodeSize],
          [0, NodeSize / 2]
        ]
      }
    }

    return {
      view: Node,
      model: Model
    }
  })
}
